/*
 * table_LexToken.c
 *
 *  Created on: 2012/04/25
 *      Author: guanxiaoying
 */
#include "../../parser/coredef.h"
typedef struct _LEXTOKEN
{
	U4	ulKind;		/* 2 */
	U4  milestone;
	AST			astLoc;		/* 3 */
	AST			astType;		/* 4 */
	AST			astParam;		/* 6 */
	AST			astPPToken;
	AST			astSymbol;	/* 5 */
} LEXTOKEN, *PLEXTOKEN;
#define TableSize  (sizeof(LEXTOKEN ))
#define TableType  PLEXTOKEN
#define stTable stLexTokenManager.memoryBlocks
#define maxTable stLexTokenManager.maxRecordNum
#define  maxNumPerBlk  (stLexTokenManager.astMaxNum_Block)

static TABLEMANAGER stLexTokenManager = {
//		U4                  usIdx;
		0,
//		PSZ				    con_pszName;    constant
		__FILE__,
//		U2					con_usSize;		constant
		TableSize,
//		U2					block_num;	　　　　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_Block;     １回設定のみ
		0,
//		S4					astTabNum_LastPage; 　　　　Reset clear  際　要
		0,
//		S4					astMaxNum_LastPage;     Reset clear  際　要
		0,
//		U4					ulMaxByte;	　　　　　　　　　　クリアしない
		0,
//		U4					con_minPageSize;　　　　　　　　　　constant
		0
};

static VOID resetListener( U4  procid, U2 index )
{
	if( procid == stLexTokenManager.u4Idx )
	{
		if( index > 0 && index < MAX_VOLUMN_OF_TABLE )
		{
			stTable[ index-1] = NULL;
		}
	}
}
static TableType core_getTable( AST index )
{
	TableType temp = (TableType)Check_Com( &stLexTokenManager, resetListener, index );
	if( temp != NULL ){ return &temp[index%maxNumPerBlk]; } return NULL;
}


static BOOL ClearTable( VOID )
{
	return Clear_Com( &stLexTokenManager );
}
static BOOL ResetTable( VOID )
{
	return Reset_Com( &stLexTokenManager );
}
static BOOL AllocTable( AST astReqArg )
{
	return AllocTable_Com( &stLexTokenManager, astReqArg, resetListener );
}
static AST getMaxLineNum( VOID )
{
	return maxTable;
}
//	U4_SIZE
static U4  getTokenKind( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->ulKind ;
}
/* set method */
static U4  setTokenKind( AST index, U4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->ulKind = value;
}
static AST  getCodeScp( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astLoc ;
}
/* set method */
static AST  setCodeScp( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astLoc = value;
}
static AST  getType( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astType ;
}
/* set method */
static AST  setType( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astType = value;
}
static CHAR*  getName( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return "";
	}
	return stCcLabelStrAccess.getStr( pTbl->astSymbol );
}
/* set method */
static AST  setName( AST index, PSZ value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astSymbol = stCcLabelStrAccess.addStr(value);
}
static AST  getParamIdx( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->astParam ;
}
/* set method */
static AST  setParamIdx( AST index, AST value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		assert_index( maxTable, index, value );
		return 0;
	}
	return pTbl->astParam = value;
}
static U4 getMark( AST index )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->milestone;
}
static U4 setMark( AST index, U4 value )
{
	TableType pTbl = core_getTable( index );
	if( pTbl == NULL )
	{
		return 0;
	}
	return pTbl->milestone = value;
}
const LEXTOKENACCESS stLexTokenAccess = {
//		BOOL (*clear)( VOID );
		ClearTable,
//		BOOL (*reset)( VOID );
		ResetTable,
//		BOOL (*alloc)( AST );
		AllocTable,
//		AST  (*getMax)( VOID );
		getMaxLineNum,
//		ACCESS_U4_FIELD tokenKind;
		{
				getTokenKind,
				setTokenKind
		},
//		ACCESS_IDX_FIELD codeScp;
		{
				getCodeScp,
				setCodeScp
		},
//		ACCESS_IDX_FIELD type;
		{
				getType,
				setType
		},
//		ACCESS_STR_FIELD name;
		{
				getName,
				setName
		},
//		ACCESS_S4_FIELD  paramIdx;
		{
				getParamIdx,
				setParamIdx
		},
		{
				getMark,
				setMark
		}
};
